package br.com.FII.DAO.assunto;

import java.util.List;

import javax.ejb.Stateless;

import br.com.FII.DAO.AbstractDAOImpl;
import br.com.FII.constants.ConstantesSistema;
import br.com.FII.model.Assunto;
import br.com.FII.utils.PropertiesUtil;

@Stateless
public class AssuntoDAOImpl extends AbstractDAOImpl<Assunto> implements AssuntoRepository {

	@SuppressWarnings( "unchecked" )
	public List<Assunto> getPorID( int id ) {
		String JPQL = PropertiesUtil.getProperty( ConstantesSistema.PROPERTIES_QUERIES, "listAssuntoByID" );
		return em.createQuery( JPQL ).setParameter( "idAssunto", id ).getResultList();
	}

	@SuppressWarnings( "unchecked" )
	public List<Assunto> getPorAssunto( String assunto ) {
		String JPQL = PropertiesUtil.getProperty( ConstantesSistema.PROPERTIES_QUERIES, "listAssuntoByAssunto" );
		return em.createQuery( JPQL ).setParameter( "assunto", assunto ).getResultList();
	}

	@SuppressWarnings( "unchecked" )
	public List<Assunto> getPorIntervaloID( int idInicial, int idFinal ) {
		String JPQL = PropertiesUtil.getProperty( ConstantesSistema.PROPERTIES_QUERIES, "listAssuntoByIDInterval" );
		return em.createQuery( JPQL ).setParameter( "idInicio", idInicial ).setParameter( "idFim", idFinal ).getResultList();
	}

	public boolean existeAssunto( Assunto assunto ) {
		String JPQL = PropertiesUtil.getProperty( ConstantesSistema.PROPERTIES_QUERIES, "existeAssunto" );
		return em.createQuery( JPQL ).setParameter( "assunto", assunto.getAssunto() ).setParameter( "codAssunto", assunto.getCodAssunto() ).getResultList().isEmpty();
	}

}
